#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

bool is_prime(int num) {
  if (num < 2) {
    return false;
  }
  for (int i = 2; i <= sqrt(num); ++i) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

int closest_prime_number(const string& s) {
  vector<string> words;
  string word;
  for (char c : s) {
    if (c == ' ') {
      words.push_back(word);
      word = "";
    } else {
      word += c;
    }
  }
  words.push_back(word);

  if (words.size() != 3) {
    cout << "Wrong input" << endl;
    return -1;
  }

  int number = 0;
  for (const string& w : words) {
    if (w == "zero") {
      number = number * 10 + 0;
    } else if (w == "one") {
      number = number * 10 + 1;
    } else if (w == "two") {
      number = number * 10 + 2;
    } else if (w == "three") {
      number = number * 10 + 3;
    } else if (w == "four") {
      number = number * 10 + 4;
    } else if (w == "five") {
      number = number * 10 + 5;
    } else if (w == "six") {
      number = number * 10 + 6;
    } else if (w == "seven") {
      number = number * 10 + 7;
    } else if (w == "eight") {
      number = number * 10 + 8;
    } else if (w == "nine") {
      number = number * 10 + 9;
    } else {
      cout << "Wrong input" << endl;
      return -1;
    }
  }

  if (100 <= number && number <= 999 && is_prime(number)) {
    return number;
  }

  int lower = number - 1;
  int upper = number + 1;

  while (true) {
    if (lower >= 100 && is_prime(lower)) {
      return lower;
    } else if (upper <= 999 && is_prime(upper)) {
      return upper;
    }
    lower--;
    upper++;
  }

  cout << "Wrong input" << endl;
  return -1;
}

int main() {
  string input_str;
  cout << "Введите три слова: ";
  getline(cin, input_str);
  int result = closest_prime_number(input_str);
  if (result != -1) {
    cout << result << endl;
  }
  return 0;
}
